﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;

namespace NotifyServices
{
   
    public partial class EditConfig : Form
    {
        ServiceList config = new ServiceList();

        public EditConfig()
        {
            InitializeComponent();
            config = new ServiceList();
            config.Load();
            
            serviceListBindingSource.DataSource = config;
            existingServicesBindingSource.DataSource = ExistingServices.GetServices(config);
            cbExistingServices.DisplayMember = "DisplayName";
            cbExistingServices.ValueMember = "ServiceName";
            serviceListBindingSource.AddingNew += new AddingNewEventHandler(serviceListBindingSource_AddingNew);
        }

        void serviceListBindingSource_AddingNew(object sender, AddingNewEventArgs e)
        {
            config.Add(new ConfigService() { ServiceName = (string)cbExistingServices.SelectedValue });
            serviceListBindingSource.ResetBindings(false);
        }

        


        private void btnSave_Click(object sender, EventArgs e)
        {
            config.Save();
            this.Hide();
        }

        private void btnAddRow_Click(object sender, EventArgs e)
        {
            serviceListBindingSource.AddNew();
            
        }

       
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 3)
            {
                serviceListBindingSource.RemoveCurrent();
            }
        }

        

        
    }
}
